package linc.fun.common.rest.http.response;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * @author linc
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
public class JsonRestResponse<T> extends Response {
    private T data;


    public static <T> JsonRestResponse<T> of(T data) {
        JsonRestResponse<T> singleResponse = new JsonRestResponse<>();
        singleResponse.setSuccess(true);
        singleResponse.setData(data);
        return singleResponse;
    }


    public static JsonRestResponse<?> buildFailure(String errCode, String errMessage) {
        JsonRestResponse<?> response = new JsonRestResponse<>();
        response.setSuccess(false);
        response.setErrCode(errCode);
        response.setErrMessage(errMessage);
        return response;
    }

    public static JsonRestResponse<?> buildSuccess() {
        JsonRestResponse<?> response = new JsonRestResponse<>();
        response.setSuccess(true);
        return response;
    }

    public interface ErrorCode {
        String INTER_ERROR = "9999";
        String MALFORMED = "9998";
        String METHOD_NOT_FOUND = "9997";
        String MISSING_PARAM = "9996";
    }
}
